<?php

namespace asyncService\message;


class redisMessage implements interfaceMessage
{
    /**
     * @var \Redis
     */
    protected $client ;

    public function __construct(array $config)
    {
        $this->client = new \Redis();
        if(!$this->client->connect($config['host'],$config['port'],$config['timeout'])){
            throw new \Exception("connect redis error!");
        }
    }

    public function pop($key){
        return $this->client->lPop($key);
    }

    public function push($key,$value){
        return $this->client->lPush($key,$value);
    }

    public function sendSignal($signal){
        return $this->client->set($signal,1);
    }

    public function removeSignal($signal){
        return $this->client->del($signal);
    }

    public function hasSignal($signal){
        return $this->client->exists($signal);
    }

    public function __destruct()
    {
        try{
            $this->client->close();
        }catch (\Exception $exception){

        }
    }
}